package com.guigu.liuzhireng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuzhireng.mapper.RoleMapper;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.liuzhireng.pojo.Role;
import com.guigu.liuzhireng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public int update(Role role) {
        return roleMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    public int insert(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int delete(Integer id) {
        return roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageVo<Role> Page(Role role, int num, int size) {
        PageHelper.startPage(num,size);
        List<Role> list = roleMapper.RoleAll(role);
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        PageVo<Role> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }

    @Override
    public List<Role> list() {
        return roleMapper.All(0);
    }
}
